home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / src / plwind.c < prev   
Encoding:
C/C++ Source or Header  |  1994-07-30  |  5.3 KB  |  189 lines

  1. /* $Id: plwind.c,v 1.8 1994/07/29 20:29:24 mjl Exp $
  2.  * $Log: plwind.c,v $
  3.  * Revision 1.8  1994/07/29  20:29:24  mjl
  4.  * Change so that window coordinates are added to the window list each time
  5.  * plwind() is called.  Contributed by Paul Casteels.
  6.  *
  7.  * Revision 1.7  1994/06/30  18:22:24  mjl
  8.  * All core source files: made another pass to eliminate warnings when using
  9.  * gcc -Wall.  Lots of cleaning up: got rid of includes of math.h or string.h
  10.  * (now included by plplot.h), and other minor changes.  Now each file has
  11.  * global access to the plstream pointer via extern; many accessor functions
  12.  * eliminated as a result.
  13. */
  14.  
  15. /*    plwind.c
  16.  
  17.     Routines for setting up world coordinates of the current viewport.
  18. */
  19.  
  20. #include "plplotP.h"
  21.  
  22. #define  dtr   0.01745329252
  23.  
  24. /*----------------------------------------------------------------------*\
  25.  * void plwind()
  26.  *
  27.  * Set up world coordinates of the viewport boundaries (2d plots).
  28. \*----------------------------------------------------------------------*/
  29.  
  30. void
  31. c_plwind(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax)
  32. {
  33.     PLINT vppxmi, vppxma, vppymi, vppyma;
  34.     PLFLT dx, dy;
  35.     PLFLT vpwxmi, vpwxma, vpwymi, vpwyma;
  36.     PLFLT vpxmi, vpxma, vpymi, vpyma;
  37.     PLFLT wmxscl, wmxoff, wmyscl, wmyoff;
  38.     CWindow w;
  39.  
  40.     if (plsc->level < 2) {
  41.     plabort("plwind: Please set up viewport first");
  42.     return;
  43.     }
  44.  
  45.     plP_gvpp(&vppxmi, &vppxma, &vppymi, &vppyma);
  46.     plP_gvpd(&vpxmi, &vpxma, &vpymi, &vpyma);
  47.  
  48. /* Best to just warn and recover on bounds errors */
  49.  
  50.     if (xmin == xmax) {
  51.     plwarn("plwind: Invalid window limits in x.");
  52.     xmin--; xmax++;
  53.     }
  54.     if (ymin == ymax) {
  55.     plwarn("plwind: Invalid window limits in y.");
  56.     ymin--; ymax++;
  57.     }
  58.  
  59.     dx = (xmax - xmin) * 1.0e-5;
  60.     dy = (ymax - ymin) * 1.0e-5;
  61.  
  62. /* The true plot window is made slightly larger than requested so that */
  63. /* the end limits will be on the graph  */
  64.  
  65.     plP_svpw((PLFLT) (xmin - dx), (PLFLT) (xmax + dx),
  66.      (PLFLT) (ymin - dy), (PLFLT) (ymax + dy));
  67.  
  68.     plP_gvpw(&vpwxmi, &vpwxma, &vpwymi, &vpwyma);
  69.  
  70. /* Compute the scaling between coordinate systems */
  71.  
  72.     dx = vpwxma - vpwxmi;
  73.     dy = vpwyma - vpwymi;
  74.  
  75.     plsc->wpxscl = (vppxma - vppxmi) / dx;
  76.     plsc->wpxoff = (xmax * vppxmi - xmin * vppxma) / dx;
  77.     plsc->wpyscl = (vppyma - vppymi) / dy;
  78.     plsc->wpyoff = (ymax * vppymi - ymin * vppyma) / dy;
  79.  
  80.     vpxmi = plP_dcmmx(vpxmi);
  81.     vpxma = plP_dcmmx(vpxma);
  82.     vpymi = plP_dcmmy(vpymi);
  83.     vpyma = plP_dcmmy(vpyma);
  84.  
  85.     wmxscl = (vpxma - vpxmi) / dx;
  86.     wmxoff = (xmax * vpxmi - xmin * vpxma) / dx;
  87.     wmyscl = (vpyma - vpymi) / dy;
  88.     wmyoff = (ymax * vpymi - ymin * vpyma) / dy;
  89.  
  90.     plP_swm(wmxscl, wmxoff, wmyscl, wmyoff);
  91.  
  92. /* Add coordinates of window to windows list */
  93. /* By Paul Casteels */
  94.  
  95.     w.wx1 = xmin;
  96.     w.wx2 = xmax;
  97.     w.wy1 = ymin;
  98.     w.wy2 = ymax;
  99.     w.vpx1 = vppxmi;
  100.     w.vpx2 = vppxma;
  101.     w.vpy1 = vppymi;
  102.     w.vpy2 = vppyma;
  103.     plAddCWindow(w);
  104.  
  105.     plsc->level = 3;
  106. }
  107.  
  108. /*----------------------------------------------------------------------*\
  109.  * void plw3d()
  110.  *
  111.  * Set up a window for three-dimensional plotting. The data are mapped
  112.  * into a box with world coordinate size "basex" by "basey" by "height",
  113.  * with the base being symmetrically positioned about zero. Thus
  114.  * the mapping between data 3-d and world 3-d coordinates is given by:
  115.  *
  116.  *   x = xmin   =>   wx = -0.5*basex
  117.  *   x = xmax   =>   wx =  0.5*basex
  118.  *   y = ymin   =>   wy = -0.5*basey
  119.  *   y = ymax   =>   wy =  0.5*basey
  120.  *   z = zmin   =>   wz =  0.0
  121.  *   z = zmax   =>   wz =  height
  122.  *
  123.  * The world coordinate box is then viewed from position "alt"-"az",
  124.  * measured in degrees. For proper operation, 0 <= alt <= 90 degrees,
  125.  * but az can be any value.
  126. \*----------------------------------------------------------------------*/
  127.  
  128. void
  129. c_plw3d(PLFLT basex, PLFLT basey, PLFLT height, PLFLT xmin0,
  130.     PLFLT xmax0, PLFLT ymin0, PLFLT ymax0, PLFLT zmin0,
  131.     PLFLT zmax0, PLFLT alt, PLFLT az)
  132. {
  133.     PLFLT xmin, xmax, ymin, ymax, zmin, zmax, d;
  134.     PLFLT cx, cy, saz, caz, salt, calt, zscale;
  135.  
  136.     if (plsc->level < 3) {
  137.     plabort("plw3d: Please set up 2-d window first");
  138.     return;
  139.     }
  140.     if (basex <= 0.0 || basey <= 0.0 || height <= 0.0) {
  141.     plabort("plw3d: Invalid world coordinate boxsize");
  142.     return;
  143.     }
  144.     if (xmin0 == xmax0 || ymin0 == ymax0 || zmin0 == zmax0) {
  145.     plabort("plw3d: Invalid axis range");
  146.     return;
  147.     }
  148.     if (alt < 0.0 || alt > 90.0) {
  149.     plabort("plw3d: Altitude must be between 0 and 90 degrees");
  150.     return;
  151.     }
  152.  
  153.     d = 1.0e-5 * (xmax0 - xmin0);
  154.     xmax = xmax0 + d;
  155.     xmin = xmin0 - d;
  156.     d = 1.0e-5 * (ymax0 - ymin0);
  157.     ymax = ymax0 + d;
  158.     ymin = ymin0 - d;
  159.     d = 1.0e-5 * (zmax0 - zmin0);
  160.     zmax = zmax0 + d;
  161.     zmin = zmin0 - d;
  162.     cx = basex / (xmax - xmin);
  163.     cy = basey / (ymax - ymin);
  164.     zscale = height / (zmax - zmin);
  165.     saz = sin(dtr * az);
  166.     caz = cos(dtr * az);
  167.     salt = sin(dtr * alt);
  168.     calt = cos(dtr * alt);
  169.  
  170.     plsc->domxmi = xmin;
  171.     plsc->domxma = xmax;
  172.     plsc->domymi = ymin;
  173.     plsc->domyma = ymax;
  174.     plsc->zzscl = zscale;
  175.     plsc->ranmi = zmin;
  176.     plsc->ranma = zmax;
  177.  
  178.     plsc->base3x = basex;
  179.     plsc->base3y = basey;
  180.     plsc->basecx = 0.5 * (xmin + xmax);
  181.     plsc->basecy = 0.5 * (ymin + ymax);
  182.  
  183.     plsc->cxx = cx * caz;
  184.     plsc->cxy = -cy * saz;
  185.     plsc->cyx = cx * saz * salt;
  186.     plsc->cyy = cy * caz * salt;
  187.     plsc->cyz = zscale * calt;
  188. }
  189.